<template>
  <div class="about">
    <h1>This is an 搜索结果 page</h1>
    <van-card
      v-for="(item, index) in result"
      :key="index"
      :title="item.title"
      :thumb="item.img"
      @click="gotodetail(item)"
    />
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: [],
      result: [],
      keyword: this.$route.query.keyword,
    };
  },
  created() {
    this.$axios.get("list.json").then((res) => {
      this.list = res.data.list;
      this.result = this.list.filter((item) => {
        return item.title.includes(this.keyword) == true;
      });
      // includes 是数组的方法 看是否含有某个字符 如果含有就返回true没有就返回 false
    });
  },
  methods: {
    gotodetail(item) {
      this.$router.push({ path: "/detail", query: { obj: item } });
    },
  },
};
</script>
